/**
 * webview 
 * 
 * @author Gill Gong
 * @date 2019-11-20
 */

 import React from "react"
 import { Platform } from "react-native"
 import { WebView } from 'react-native-webview'
//import console = require("console");

 class Zw3dAdpter extends React.Component {
  static navigationOptions = () => {
  
    return {
      title: '中望3D模型'
    }
  }

  constructor(options) {
    super(options)

    this.webViewRef = null
  }

  render() {
    let source = Platform.OS === 'ios' ?
      { uri: '../assets/zw_3d_view.html' }:
        { uri: 'file:///android_asset/zw_3d_view.html' }

    return (
      <WebView
        ref={ (ref)=> this.webViewRef = ref }
        originWhitelist={['*']}
        source={ source }
        onLoad = { ()=> this.showZw3DView() }
        onMessage={ this.handleMessage }
      />
    )
  }

  handleMessage(data) {

    console.log("=======================================")
    console.log(data.nativeEvent.data)
  }

  sendMessage(filePath, cadServer) {

    this.webViewRef.postMessage(
      JSON.stringify({
        cmd: 'setUrl',
        params: {
          url: filePath,
          cadServer: cadServer
        }
      })
    )
  }

  showZw3DView() {
    let filePath = "http://gateway.demo.jwis.cn/file/file/getZ3dsFileByOid/1173853636971913216/1173853639781908480/ASM0005.ASM.z3ds"
    let cadServer = "http://gateway.demo.jwis.cn/cad"

    setTimeout(()=>{
      this.sendMessage(filePath, cadServer)
    }, 500)
  }
 }

 export default Zw3dAdpter
